Imports System.Collections.Generic

Public Class ColumnList
    Inherits System.MarshalByRefObject

    Private _columns As List(Of Column)
    Private _active As Column

    Public Sub New()
        _columns = New List(Of Column)
    End Sub

    Public Sub Add(ByVal col As Column)
        _columns.Add(col)
        _active = col
    End Sub

    Default Public ReadOnly Property Item(ByVal i As Integer) As Column
        Get
            _active = CType(_columns(i), Column)
            Return _active
        End Get
    End Property

    Default Public ReadOnly Property Item(ByVal columnName As String) As Column
        Get
            For i As Integer = 0 To _columns.Count - 1
                If CType(_columns(i), Column).ColumnName = columnName Then
                    _active = CType(_columns(i), Column)
                    Return _active
                End If
            Next
            _active = Nothing
            Return Nothing
        End Get
    End Property

    Public Sub SetNoActiveColumn()
        _active = Nothing
    End Sub

    Public Property ActiveColumn() As Column
        Set(ByVal value As Column)
            _active = value
        End Set
        Get
            Return _active
        End Get
    End Property

    Public ReadOnly Property Count() As Integer
        Get
            Return _columns.Count
        End Get
    End Property

    Public ReadOnly Property Columns() As List(Of Column)
        Get
            Return Me._columns
        End Get
    End Property

    Public ReadOnly Property Columns(ByVal name As String) As Column
        Get
            For i As Integer = 0 To Me._columns.Count - 1
                If Me._columns(i).ColumnName = name Then
                    Return Me._columns(i)
                End If
            Next
            Return Nothing
        End Get
    End Property

End Class
